<div id="content-header">
    <h1><?php echo __d('system','List Node Types');?></h1>
</div>
<div id="breadcrumb">
    <a href="#" title="Go to Home" class="tip-bottom"><i class="icon-th-list"></i> <?php echo __d('system','Home');?></a>
</div>
<div class="container-fluid">
<div class="row-fluid">
</div>
<div class="row-fluid">
    <div class="span12">
        <?php
            $data = $this->request->data;
            if(($data['NodeType']['set_menu']==1)||($data['NodeType']['menu_child']==1)){
                $dipslay = 'block';
            }else{$dipslay = 'none';}    
            echo $this->Form->create('NodeType', array('id' => 'paginate','class'=>'form-horizontal', 'action' => 'edit', 'url' => $this->request->here(false), 'type' => 'post',
                    'inputDefaults' => array('label' => false, 'format' => array('before', 'label', 'between', 'input', 'after', 'error'))));
            echo $this->element('toolbar');
        ?>									
        <div class="widget-box">
            <?php 
                $fieldsets['name'] = $this->Form->input('name', array(
                        'label' => array('text'=>__d('system','Name'),'class' => 'control-label'),
                        'between' => '<div class="controls">',
                        'div' => array('class' => 'control-group'),
                        'after' => '</div>',
                        'type' => 'text'));
                $fieldsets['enabled'] = $this->Form->input('enabled', array(
                        'label' => array('text'=>__d('system','Menu Backend'),'class' => 'control-label'),
                        'between' => '<div class="controls">',
                        'div' => array('class' => 'control-group'),
                        'after' => '</div>',
                        'type' => 'checkbox'));
                $fieldsets['set_menu'] = $this->Form->input('set_menu', array(
                        'label' => array('text'=>__d('system','Show is menu'),'class' => 'control-label'),        
                        'between' => '<div class="controls">',
                        'div' => array('class' => 'control-group'),
                        'default'=>0,
                        'class'=>'set_menu', 
                        'after' => '</div>',
                        'type' => 'checkbox'));
                $fieldsets['allow_share'] = $this->Form->input('allow_share', array(
                        'label' => array('text'=>__d('system','Allow Share'),'class' => 'control-label'),        
                        'between' => '<div class="controls">',
                        'div' => array('class' => 'control-group'),
                        'default'=>0,                                            
                        'after' => '</div>',
                        'type' => 'checkbox'));
                $fieldsets['menu_child'] = $this->Form->input('menu_child', array(
                        'label' => array('text'=>'Sub Menu','class' => 'control-label'),        
                        'between' => '<div class="controls">',
                        'div' => array('class' => 'control-group'),
                        'default'=>0, 
                        'class'=>'set_menu',                                 
                        'after' => '</div>',
                        'type' => 'checkbox'));    
                $fieldsets['alias'] = $this->Form->input('alias', array(
                        'label' => array('text'=>__d('system','Alias'),'class' => 'control-label'),
                        'between' => '<div class="controls">',
                        'div' => array('class' => 'control-group activex','style'=>'display:'.$dipslay),
                        'after' => '</div>',
                        'type' => 'text'));        
                $fieldsets['action'] = $this->Form->input('action', array(
                        'label' => array('text'=>__d('system','Choose Action'),'class' => 'control-label'),
                        'between' => '<div class="controls">',
                        'div' => array('class' => 'control-group activex','style'=>'display:'.$dipslay),                
                        'after' => '</div>',
                        'empty'=>__d('system','-----Select Action-----'), 
                        'options'=>$listAction,       
                        'type' => 'select'));
                $fieldsets['kind_node_type_id'] = $this->Form->input('kind_node_type_id', array(
                        'label' => array('text'=>__d('system','Choose Kind Node Type'),'class' => 'control-label'),
                        'between' => '<div class="controls">',                    
                        'div' => array('class' => 'control-group activex'),                    
                        'after' => '</div>',                    
                        'options'=>$kindNodeType,
                        'empty'=>__d('system','-----Select kind node type-----'),       
                        'type' => 'select')); 
                $fieldsets['set_image'] = $this->Form->input('set_image', array(
                        'label' => array('text'=>__d('system','Show image'),'class' => 'control-label'),        
                        'between' => '<div class="controls">',
                        'div' => array('class' => 'control-group'),       
                        'after' => '</div>',
                        'type' => 'checkbox'));
                $fieldsets['description'] = $this->Form->input('description', array(
                        'label' => array('text'=>__d('system','Description'),'class' =>'control-label'),
                        'between' => '<div class="controls">',
                        'div' => array('class' => 'control-group'),
                        'after' => '</div>',
                        'type' => 'textarea'));         
                $listSubSite = array(); 
                $listSubSite = Configure::read('App.themes.listSubSite');                      
                $fieldsets['sub_site'] = $this->Form->input('sub_site', array(
                        'label' => array('text'=>__d('system','Sub site'),'class' => 'control-label'),
                        'between' => '<div class="controls">',
                        'div' => array('class' => 'control-group'),
                        'options'=>$listSubSite,
                        'after' => '</div>',
                        'type' => 'select'));
                $fieldsets['image'] = $this->Form->input('image', array(
                        'label' => array('text'=>__d('system','Image'),'class' => 'control-label'),
                        'between' => '<div class="controls">',
                        'div' => array('class' => 'control-group'),
                        'after' => '</div>',
                        'type' => 'file'));                    

            ?>        

            <?php
                echo $this->Layout->form($_layouts, $fieldsets);
            ?>
            <!--For add more gallery-->
            <label for="NodeFieldProjectImage" style="padding-left: 10px; font-weight: bold;"><?php echo __d("system", "Image Relation")?></label>
            <br />
            <span style="padding-left: 10px;"><?php echo __d("system", "Size: 900x470")?></span>
            <div class="rowset clearfix project-image">
                <div class="column coldouble">
                    <?php echo $this->Form->input('ProImage', array(
                                'label' => false,
                                'type'  => 'file', 
                                'name' => 'data[ProImage][]'));?>
                </div>
            </div>
            <div id="cloneImage"></div>
            <a style="padding-left: 10px; clear: both; display: block;" href="javascript:add_more();"><?php echo __d("system", "Add more image")?></a>                
            <!--End-->
            <!--For show list image-->
            <?php if(!empty($galleries)):?>            
                <?php 
                    foreach($galleries as $key=> $image):                        
                        if(!empty($image)):                        
                            $thumbnail_name = $image; 
                            endif;            
                    ?>
                    <span style="padding-top: 15px; display: block; float: left;">
                        <a id="image_<?php echo $key;?>" href=""><?php echo $this->Html->image($thumbnail_name, array('width'=>'100', 'height'=>'100', 'alt'=> 'Image','style'=>'width:100px !important;height:100px !important'));?></a>

                        <a id="image_del_<?php echo $key;?>" href="javascript:void(0);" onclick="delete_image('<?php echo $key?>');"><?php echo __d("system", "Delete")?></a>
                    </span>
                    <?php endforeach;?>                       
                <?php endif;?>
            <!--End-->
        </div>	
        <!--List Field-->
            <div class="list-chk-node-type"></div>
            <input type="hidden" name="hd-id-node-type" id="hd-get-id-node-type" value="<?php echo $id;?>"/>
        <!--End-->
        <?php
            echo $this->Form->hidden('Paginate.task', array('id' => 'task', 'value' => ''));
            echo $this->Form->end();
        ?>        								
    </div>	
</div>
<script type="text/javascript">
    jQuery(document).ready(function($){
            $('<span>Size: 1600x850</span>').insertAfter("#NodeFieldBackgroundImage");
            $('<span>Enter a valid number: (int)</span>').insertAfter("#NodeFieldBackgroundPiority");
            //developer by tunv@appdev.vn
            var _kind_node_type = $('#NodeTypeKindNodeTypeId').val(); 
            var _id = '<?php echo $id;?>';            
            if(_kind_node_type!=''){
                load_field(_kind_node_type,_id);                
            }                                    
            //end                        
    });
    function add_more(){
        var element= jQuery("#cloneImage").prev();
        jQuery(element).clone().insertBefore("#cloneImage");
        var $this = Green.Elfinder;
        jQuery('form input.file-upload').prop('readonly' , true).click(function(){
                $this.show(jQuery(this));
        });
    }
    function delete_image(id){
        if (confirm("Are you sure you want to delete?")) {
            var href= "<?php echo '/node/node/delete_image/'?>"+id;
            jQuery.ajax({
                    url: href,
                    type: "GET",
                    success: function(data) {           
                        jQuery('#image_'+id).remove();
                        jQuery('#image_del_'+id).remove();
                        //alert('Load was performed.');
                    }
            });
        }
    }
</script>